Styling Layers and Maps

In [1]:
import pandas as pd

from cartoframes.viz import Map, Layer

Widgets

In [2]:
seattle_collisions = pd.read_csv('data/seattle_collisions.csv')

from cartoframes.viz.widgets import formula_widget, category_widget

Map(
    Layer(
        seattle_collisions,
        widgets=[
            formula_widget(
                'pedcount',
                'sum',
                title='Pedestrians Involved'
            ),
            formula_widget(
                'pedcylcount',
                'sum',
                title='Cyclists Involved'
            ),
            category_widget(
                'collisiontype',
                title='Collision Type'
            )
        ]
    )
)
Out[2]:

Layers and Maps

Layer structure:

Layer(
    source=...,
    style=...,
    legend=...,
    widgets=...
)
  • source can be a DataFrame, GeoDataFrame or CartoFrames' Dataset (table or query).
  • style takes a CartoVL styling expression
  • popup can be a Popup object, or a dict with hover and/or click as keys
  • legend can be a Legend object, or just a simple dictionary
  • widgets takes list of Widget objects

Maps allow you to add several layers, select the basemap, set a viewport, and others.

In [3]:
from cartoframes.viz import Widget, basemaps

df = pd.read_csv('data/maxhi_20190717_72.csv')

Map ([
    Layer(
        df,
        '''
            color: ramp(linear($value,globalMIN($value),globalMAX($value)),[turquoise, yellow, red])
            filter: animation(linear($value,globalMIN($value),globalMAX($value)), 20, fade(0.1, hold))
            strokeWidth: 0
            width: 4
        ''',
        legend={
            'type':'color-continuous-polygon',
            'title': 'Max Heat Index for July 20, 2019',
            'description': 'Degrees (°F)',
            'footer': 'Issued: 7/17/19 | Source: NOAA Weather Predicition Center'
        },
        widgets=[
                Widget(
                    'formula',
                    value='viewportMAX($value)',
                    title='Max Degrees (°F)',
                ),
                Widget('time-series', value='value', title='Animation by Temperature'),
          
        ],
    )
    ],
    basemap=basemaps.darkmatter,
    show_info=True,
    viewport={'zoom': 2.5, 'lat': 37.572586, 'lng': -110.638529},
)
Out[3]: